#!/bin/bash

# 设置变量
BUILD_DIR="dist"
WHEEL_FILE="*.whl"
PRIVATE_REPO_URL="https://nexus.xinhouai.com/repository/pip3-hosted/"
TWINE_USERNAME="sp_hrz@qq.com"
TWINE_PASSWORD="shenpeng1980"

# 定义函数：构建项目
build() {
    echo "Building project..."
#    pip freeze > requirements.txt
    python setup.py sdist bdist_wheel
}

# 定义函数：重新构建项目（清除旧的构建文件）
rebuild() {
    echo "Rebuilding project..."
    clean
    build
}

# 定义函数：清除旧的构建文件
clean() {
    echo "Cleaning up..."
    rm -rf $BUILD_DIR build *.egg-info
}

# 定义函数：更新私服
upload() {
    echo "Uploading to private repository..."
    twine upload --repository-url $PRIVATE_REPO_URL -u $TWINE_USERNAME -p $TWINE_PASSWORD $BUILD_DIR/$WHEEL_FILE
}

# 定义函数：部署项目（构建并上传）
deploy() {
    echo "Deploying project..."
    rebuild
    upload
}

# 检查命令行参数
case "$1" in
    build)
        build
        ;;
    rebuild)
        rebuild
        ;;
    clean)
        clean
        ;;
    upload)
        upload
        ;;
    deploy)
        deploy
        ;;
    *)
        echo "Usage: $0 {build|rebuild|clean|update|deploy}"
        exit 1
esac

exit 0
